<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
    <head>
        <title>Dynamic SVGIcon demo</title>
        <script type="text/javascript">

          var _gaq = _gaq || [];
          _gaq.push(['_setAccount', 'UA-17414889-3']);
          _gaq.push(['_trackPageview']);

          (function() {
            var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
            ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
            var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
          })();

        </script>
    </head>
    <body>

    <h2>Dynamic SVGIcon demo</h2>

    <p><img src="svgIODemoScreenShot.png" align="right" />This is a minimal program which demonstrates a correct way to create SVG Icons and render them to the screen.  This particular example generates the SVG document dynamically.  You can also load SVG documents from file.</p>

    <p>This example can be found in the SVG Salamnder source.</p>
  
<pre>

package com.kitfox.svg.example;

import java.awt.*;
import java.net.*;
import java.io.*;
import javax.swing.*;

import com.kitfox.svg.*;
import com.kitfox.svg.app.beans.*;


class IconPanel extends JPanel
{
    public static final long serialVersionUID = 0;
    
    final SVGIcon icon;
    
    
    public IconPanel()
    {
        StringReader reader = new StringReader(makeDynamicSVG());
        URI uri = SVGCache.getSVGUniverse().loadSVG(reader, "myImage"); 
        icon = new SVGIcon();
        icon.setSvgURI(uri);
        
        setPreferredSize(new Dimension(400, 400));
    }
    
    public void paintComponent(Graphics g)
    {
        final int width = getWidth();
        final int height = getHeight();
        
        g.setColor(getBackground());
        g.fillRect(0, 0, width, height);
        
        icon.paintIcon(this, g, 0, 0);
    }
    
    private String makeDynamicSVG()
    {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        
        pw.println("&lt;svg width=\"400\" height=\"400\" style=\"fill:none;stroke-width:4\"&gt;");
        pw.println("    &lt;circle cx=\"200\" cy=\"200\" r=\"200\" style=\"stroke:blue\"/&gt;");
        pw.println("    &lt;circle cx=\"140\" cy=\"140\" r=\"40\" style=\"stroke:red\"/&gt;");
        pw.println("    &lt;circle cx=\"260\" cy=\"140\" r=\"40\" style=\"stroke:red\"/&gt;");
        pw.println("    &lt;polyline points=\"100 300 150 340 250 240 300 300\" style=\"stroke:red\"/&gt;");
        pw.println("&lt;/svg&gt;");
        
        pw.close();
        return sw.toString();
    }
}

/**
 *
 * @author  kitfox
 */
public class SVGIODemoFrame extends javax.swing.JFrame
{
    public static final long serialVersionUID = 0;
    
    IconPanel panel = new IconPanel();
    
    /** Creates new form SVGIconDemo */
    public SVGIODemoFrame()
    {
        initComponents();

        this.getContentPane().add(panel, BorderLayout.CENTER);
        
        pack();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents()
    {

        setLayout(new java.awt.BorderLayout());

    }
    
    public static void main(String args[])
    {
        java.awt.EventQueue.invokeLater(new Runnable()
        {
            public void run()
            {
                new SVGIODemoFrame().setVisible(true);
            }
        });
    }
    
}
</pre>
  
    </body>
</html>
